package com.example.login;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Objects;

/**
 * @author mucd
 * 2021年06月22日  17:29
 */

@WebServlet(value = "/MySession")
public class MySession extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        HttpSession session = req.getSession();
        String  attribute =(String) session.getAttribute("user");
        //登陆过
        if (attribute != null) {
            String user = (String) session.getAttribute("user");
            req.getRequestDispatcher("limit?page=1").forward(req,resp);
            //resp.getWriter().write("<h1>欢迎 : "+user+"<h1>");
        }
    }

}